/* 
 * Copyright (C) 2013, 2014 lex xiang
 *
 * file:	app/command.h
 * history:	2013 Juy 25 created by lex
 * comment:
 */

#ifndef __COMMAND_H__
#define __COMMAND_H__

#include "list.h"
#include "rbtree.h"
#include "shell.h"
#include "types.h"

#define LEN_CMD_HELP_MAX	128
#define LEN_CMD_USAGE_MAX	256

struct cmd_desc_s {
	char	help[LEN_CMD_HELP_MAX];
	char	usage[LEN_CMD_USAGE_MAX];
};
struct view_s;
/* command table info -
 * name: command name
 * curr_view: current view of the command
 * curr_vwnm: name of the current view
 * prev_view: previous view of the command
 * prev_vwnm: name of the previous view
 * cmd: the function pointer of the command action
 * help: what the command do
 * usage: how the command used
 * node: red black tree node what is used for search the command
 */
struct command_s {
	struct list_head link;
	struct rb_node	node;

	char		*name;

	struct view_s	*curr_view;
	char		*curr_vwnm;
	struct view_s	*prev_view;
	char		*prev_vwnm;

	void	(*cmd)(struct command_s *, struct shell *);
	struct cmd_desc_s *cmd_desc;
};

#define CMD_ENTRY(name, cvwnm, pvwnm, cmd, desc)	\
	{{NULL, NULL}, INIT_RB_NODE(), #name, NULL, #cvwnm, NULL, #pvwnm, cmd, desc}

extern struct command_s boot_cmd[];
extern s32 get_nr_cmd();

#endif	/* end of __COMMAND_H__ */
